/**
 * Created by HUANGFR2 on 8/21/2016.
 */
angular.module('audit_merchant').service('MerchantService', function ($http) {
    var service = {};

    service.updateMerchantStatus = function(merchant, status){
        $http.put('/merchant', {mid: merchant._id, status: status})
            .then(function(res) {
                var data = res.data;
                if (data.msg == 'SUCCESS') {
                    merchant.status = status;
                } else {
                    alert('operation error : ' + data.error);
                }
            }, function(err) {
                alert('operation error : ' + err);
            })
    };

    service.openWarningModal = function ($uibModal, $scope, merchant) {
        var modalInstance = $uibModal.open({
            animation: true,
            ariaLabelledBy: 'modal-title',
            ariaDescribedBy: 'modal-body',
            templateUrl: 'merchantWarning_modal.html',
            controller: 'merchantWarningModalController',
            size: 'sm',
            resolve: {
                parentScope: function () {
                    return $scope
                },
                merchant: function () {
                    return merchant
                }
            }
        });
        return modalInstance;
    };

    return service;
});

angular.module('audit_merchant').filter('convertStatus', function () {

    return function (status) {
        switch (status){
            case 0 : return 'Pending audit';
            case 1 : return 'Audit pass';
            case 2 : return 'Audit Refuse';
            case 3 : return 'Blocked';
        }
    }
});